package com.chouren.goandroid.http.response.handler;

import com.chouren.goandroid.http.comm.KeyValuePair;
import com.chouren.goandroid.http.exception.HttpException;
import com.chouren.goandroid.http.response.HttpStatus;
import com.chouren.goandroid.http.response.Response;

public abstract class HttpResponseHandler {
	protected abstract void onSuccess(Response res, HttpStatus status, KeyValuePair[] headers);

	protected abstract void onFailure(Response res, HttpException e);

	public HttpResponseHandler handleResponse(Response res) {
		if (res != null) {
			HttpException e = res.getException();
			if (e == null) {
				onSuccess(res, res.getHttpStatus(), res.getHeaders());
			} else {
				onFailure(res, e);
			}
		}
		return this;
	}
}
